package cn.com.chengmandian.sls.utils;

import cn.com.chengmandian.sls.constants.EcuLogType;
import cn.com.chengmandian.sls.pojo.EcuLogData;

public class EcuLogBuilder {
    private static String productKey = "UNKNOWN";

    public static EcuLogBuilder instance;

    public static EcuLogBuilder me() {
        if (instance == null) instance = new EcuLogBuilder();
        return instance;
    }

    public void init(String productKey) {
        this.productKey = productKey;
    }

    // 线程其它消息输出
    public String other(String message, String channelId) {
        return new EcuLogData().setProductKey(productKey)
                .setChannelId(channelId)
                .setMessage(message)
                .toString();
    }

    // 线程设备其它消息输出
    public String other(String message, String channelId, String deviceNo) {
        return new EcuLogData().setProductKey(productKey)
                .setChannelId(channelId)
                .setMessage(message)
                .setDeviceNo(deviceNo)
                .toString();
    }

    // 线程设备其它消息输出
    public String other(String message, String channelId, String deviceNo, Object data) {
        return new EcuLogData().setProductKey(productKey)
                .setChannelId(channelId)
                .setMessage(message)
                .setDeviceNo(deviceNo)
                .setData(data != null ? data.toString() : null)
                .toString();
    }

    // 线程错误消息输出
    public String exception(String message, String channelId) {
        return new EcuLogData().setType(EcuLogType.EXCEPTION.name())
                .setProductKey(productKey)
                .setChannelId(channelId)
                .setMessage(message)
                .toString();
    }

    // 线程设备错误消息输出
    public String exception(String message, String channelId, String deviceNo) {
        return new EcuLogData().setType(EcuLogType.EXCEPTION.name())
                .setProductKey(productKey)
                .setChannelId(channelId)
                .setMessage(message)
                .setDeviceNo(deviceNo)
                .toString();
    }

    // 线程自定义消息输出
    public String write(String message, EcuLogType logType, String channelId) {
        return new EcuLogData().setType(logType.name())
                .setProductKey(productKey)
                .setChannelId(channelId)
                .setMessage(message)
                .toString();
    }

    // 线程设备自定义消息输出
    public String write(String message, EcuLogType logType, String channelId, String deviceNo) {
        return new EcuLogData().setType(logType.name())
                .setProductKey(productKey)
                .setChannelId(channelId)
                .setDeviceNo(deviceNo)
                .setMessage(message)
                .toString();
    }

    // 线程自定义消息输出 + 数据
    public String write(String message, EcuLogType logType, String channelId, Object data) {
        return new EcuLogData().setType(logType.name())
                .setProductKey(productKey)
                .setChannelId(channelId)
                .setMessage(message)
                .setData(data != null ? data.toString() : null)
                .toString();
    }

    // 线程设备自定义消息输出 + 数据
    public String write(String message, EcuLogType logType, String channelId, String deviceNo, Object data) {
        return new EcuLogData().setType(logType.name())
                .setProductKey(productKey)
                .setChannelId(channelId)
                .setDeviceNo(deviceNo)
                .setMessage(message)
                .setData(data != null ? data.toString() : null)
                .toString();
    }
}
